package arith;

import java.text.DecimalFormat;

public class Numbers implements Input {

	double number;
	String prob;
	
	Numbers(double n, String s){
		number = n;
		prob = s;
	}
	
	public int id() {
		return 0;
	}

	public double value() {
		return number;
	}
	
	public String toString(){
		DecimalFormat df = new DecimalFormat("0.##");
		return df.format(number);
	}
	
	public Numbers add(Numbers num){
		String part1;
		String part2;
		if(this.prob.equalsIgnoreCase("")){
			part1 = this.toString();
		}else{
			part1 = "("+this.prob+")";
		}
		if(num.prob.equalsIgnoreCase("")){
			part2 = num.toString();
		}else{
			part2 = "(" + num.prob + ")";
		}
		return new Numbers(number + num.number, part1+" + "+part2);
	}
	
	public Numbers sub(Numbers num){
		String part1;
		String part2;
		if(this.prob.equalsIgnoreCase("")){
			part1 = this.toString();
		}else{
			part1 = "("+this.prob+")";
		}
		if(num.prob.equalsIgnoreCase("")){
			part2 = num.toString();
		}else{
			part2 = "(" + num.prob + ")";
		}
		return new Numbers(number - num.number, part1+" - "+part2);
	}

	public Numbers mult(Numbers num){
		String part1;
		String part2;
		if(this.prob.equalsIgnoreCase("")){
			part1 = this.toString();
		}else{
			part1 = "("+this.prob+")";
		}
		if(num.prob.equalsIgnoreCase("")){
			part2 = num.toString();
		}else{
			part2 = "(" + num.prob + ")";
		}
		return new Numbers(number * num.number, part1+" * "+part2);
	}
	
	public Numbers div(Numbers num){
		String part1;
		String part2;
		if(this.prob.equalsIgnoreCase("")){
			part1 = this.toString();
		}else{
			part1 = "("+this.prob+")";
		}
		if(num.prob.equalsIgnoreCase("")){
			part2 = num.toString();
		}else{
			part2 = "(" + num.prob + ")";
		}
		if(num.number == 0){
			return new Numbers(num.number/number, part2 + " / " + part1);
		}else{
			return new Numbers(number/num.number, part1 + " / " + part2);
		}
	}
	
}